package AWT.事件监听;

import java.awt.*;
import java.awt.event.*;

public class text {
    public static void main(String[] args) {

        wbk wbk = new wbk();
    }
}

class wbk extends Frame {
    public wbk(){
        super("文本框");
        TextField textField = new TextField();
        add(textField);
        pack();
        setVisible(true);

        //设置替换编码
        textField.setEchoChar('*');
        //文本事件监听
        textField.addActionListener(new wbsj());
        addWindowListener(new cksj());

    }
    public class cksj implements WindowListener {

        @Override
        public void windowOpened(WindowEvent e) {

        }

        @Override
        public void windowClosing(WindowEvent e) {
            System.out.println(e);
            System.exit(1);
        }

        @Override
        public void windowClosed(WindowEvent e) {

        }

        @Override
        public void windowIconified(WindowEvent e) {

        }

        @Override
        public void windowDeiconified(WindowEvent e) {

        }

        @Override
        public void windowActivated(WindowEvent e) {

        }

        @Override
        public void windowDeactivated(WindowEvent e) {

        }
    }

}
class wbsj implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println(e.getActionCommand());//获取输入内容
//        System.out.println("111");
        TextField fa= (TextField) e.getSource();//获取资源，返回一Object个对象
        System.out.println(fa.getText());//获取输入框的文本
        fa.setText(null);//清除输入的内容，设置文本框内容为null
    }

}